//
//  MyClass.swift
//  SwiftStudy
//
//  Created by wangtian on 15/7/29.
//  Copyright (c) 2015年 wangtian. All rights reserved.
//

import Foundation

class MyClass:ExpressibleByBooleanLiteral
{
    var cProperty:String?
    lazy var cArray = [AnyObject]()
    init()
    {
    
    }
    required init(booleanLiteral value: BooleanLiteralType)
    {
        if value
        {
            self.cProperty = "true"
        }
        else
        {
            self.cProperty = "false"
        }
    }
    
    subscript(index:Int) -> String?
    {
        get
        {
            return self.cProperty
        }
        set(newValue)
        {
            self.cProperty = newValue
        }
    }
  
    var a : Int?
    {
        get
        {
            if self.a == nil
            {
                self.a = 0
            }
            return self.a! + 1
        }
        set(newValue)
        {
            self.a = newValue
        }
    }

    var b : String?
    {
        willSet(newValue)
        {
            print("newValue = \(newValue)")
        }
        didSet(oldValue)
        {
            print("oldValue = \(oldValue)")
        }
    }
}

enum Myenum
{
    case one,two,three
    case four(String)
    init(initfour four:String) {
        
        self = Myenum.four(four)
    }
}

func + (left:MyClass,right:MyClass) -> MyClass
{
    let result : MyClass = MyClass()
    if (left.cProperty != nil && right.cProperty != nil)
    {
        result.cProperty = left.cProperty! + right.cProperty!
    }
    return result
}

func + (left:Myenum, right:Myenum) -> Myenum
{
    let myEnum:Myenum = Myenum.one
    return myEnum
}

prefix func !( a:Myenum ) -> Myenum
{
    return Myenum.one
}
